package xcmg.device.web.basic;

import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import xcmg.device.dao.entity.SendMethodDictionaryDO;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.infra.StringUtil;
import xcmg.device.service.basic.SendMethodDictionaryService;
import xcmg.device.service.vo.basic.SendMethodDictionaryVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;

import java.util.Arrays;
import java.util.List;


/**
 * 发货方式字典操作
 * @Author huhuawei
 */
@RequestMapping("/sendMethodDictionary")
@RestController
public class SendMethodDictionaryController extends BasicController{

    @Autowired
    private SendMethodDictionaryService sendMethodDictionaryService;

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "查询发货方式（多个）")
    public ActionResult list(@RequestBody SendMethodDictionaryVO sendMethodDictionaryVO) throws Exception{
        if(StringUtil.isEmpty(sendMethodDictionaryVO.getOrgId())){
            sendMethodDictionaryVO.setOrgId(getOrgId());
        }
        List<SendMethodDictionaryDO> list=sendMethodDictionaryService.list(sendMethodDictionaryVO);
        return actionValueResult(list);
    }
    
    @RequestMapping(value = "/listSendMethodWithDataDictory",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "查询发货方式（多个）")
    public ActionResult listSendMethodWithDataDictory(@RequestBody SendMethodDictionaryVO sendMethodDictionaryVO) throws Exception {
    	if(StringUtil.isEmpty(sendMethodDictionaryVO.getOrgId())){
            sendMethodDictionaryVO.setOrgId(getOrgId());
        }
        List<SendMethodDictionaryDO> list=sendMethodDictionaryService.listSendMethodWithDataDictory(sendMethodDictionaryVO);
        return actionValueResult(list);
    }
    
    @RequestMapping(value = "/listDirectSendMethod",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "查询发货方式（多个）")
    public ActionResult listDirectSendMethod() {

    	/**
    	SendMethodDictionaryVO sendMethodDictionaryVO = new SendMethodDictionaryVO();
    	sendMethodDictionaryVO.setpId("0");
    	sendMethodDictionaryVO.setOrgId(orgId);
    	*/
    	return actionValueResult(sendMethodDictionaryService.listDirectSendMethod());
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "添加发货方式")
    public ActionResult add(@RequestBody SendMethodDictionaryVO model) throws Exception{

        model.setCreateId(getUserId());
        model.setUpdateId(getUserId());
        model.setOrgId(getOrgId());
        ErrorCode ret=sendMethodDictionaryService.add(model);
        return actionResult(ret);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "更新发货方式")
    public ActionResult update(@RequestBody SendMethodDictionaryVO model)throws Exception{
        if(model==null){
            return actionResult(ErrorCode.IllegalArument);
        }
        model.setUpdateId(getUserId());
        model.setOrgId(getOrgId());
        ErrorCode ret=sendMethodDictionaryService.update(model);
        return actionResult(ret);
    }

    @RequestMapping(value = "/remove",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult remove(@RequestBody SendMethodDictionaryVO model){
        String[] ids = model.getIds();
        if(ids==null||ids.length==0){
            return actionResult(ErrorCode.IllegalArument);
        }
        ErrorCode ret=sendMethodDictionaryService.remove(Arrays.asList(ids));
        return actionResult(ret);
    }

    @RequestMapping(value = "/item",method = RequestMethod.GET)
    @FastMappingInfo(needLogin = true)
    public ActionResult item(String id){
        if(StringUtils.isEmpty(id)){
            return actionResult(ErrorCode.IllegalArument);
        }
        SendMethodDictionaryVO result=sendMethodDictionaryService.item(id);
        return actionValueResult(result);
    }

}
